home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2004 #2 / Amiga Plus CD - 2004 - No. 02.iso / AmigaPlus / Tools / Development / AmigaTalk / general / Block.st < prev    next >
Encoding:
Text File  |  2004-01-31  |  1.5 KB  |  80 lines

  1. "---------------------------------------------------------------"
  2. "  Block Class.
  3.  
  4.    Note how whileTrue: and whileFalse: depend upon the parser
  5.    optimizing the loops into control flow, rather than message
  6.    passing.  If this were not the case, whileTrue: would have to
  7.    be implemented using recursion, as follows:
  8.  
  9.    whileTrue: aBlock
  10.       (self value)
  11.          ifFalse: [^nil].
  12.  
  13.       aBlock value.
  14.  
  15.       ^ self whileTrue: aBlock
  16. "
  17. "---------------------------------------------------------------"
  18.  
  19. Class Block :Object
  20. [
  21.    numArgs
  22.       ^ <primitive 144 0 self> " (unused primitive 144) Added on 18-Nov-2002 (JTS) "
  23. |      
  24.    newProcess
  25.       <primitive 144 1 self 0>.
  26.       
  27.       ^ <primitive 141 self>
  28. |
  29.    newProcessWith: argumentArray
  30.       <primitive 144 1 self (argumentArray size)>.
  31.  
  32.       ^ <primitive 141 self argumentArray>
  33. |
  34.    fork
  35.       self newProcess resume.
  36.  
  37.       ^ nil
  38. |
  39.    forkWith: argumentArray
  40.       (self newProcessWith: argumentArray) resume.
  41.  
  42.       ^ nil
  43. |
  44.    whileTrue
  45.       ^ [self value ] whileTrue: []
  46. |
  47.    whileTrue: aBlock
  48.       ^ [ self value ] whileTrue: [ aBlock value ]
  49. |
  50.    whileFalse
  51.       ^ [ self value ] whileFalse: []
  52. |
  53.    whileFalse: aBlock
  54.       ^ [ self value ] whileFalse: [ aBlock value ]
  55. |
  56.    value
  57.  
  58.       <primitive 140  0>
  59. |
  60.    value: a
  61.  
  62.       <primitive 140  1>
  63. |
  64.    value: a value: b
  65.  
  66.       <primitive 140  2>
  67. |
  68.    value: a value: b value: c
  69.  
  70.       <primitive 140  3>
  71. |
  72.    value: a value: b value: c value: d
  73.  
  74.       <primitive 140  4>
  75. |
  76.    value: a value: b value: c value: d value: e
  77.  
  78.       <primitive 140  5>
  79. ]
  80.